{% extends 'home/public/index.html' %}


{% block title %}
<title>我的订单</title>
{% endblock %}

{% block css %}

<link rel="stylesheet" type="text/css" href="/static/home/css/order.css">
<link rel="stylesheet" type="text/css" href="/static/home/css/order-app.css">
        
{% endblock %}

{% block con %}
<!-- 导航 E-->
<!-- 主内容区域 -->

<div class="mainbody order">
    <div class="container">
        <!-- 面包屑导航 -->
        <div class="crumbs col-xs-12 col-sm-12">
            <ol class="breadcrumb">
                <li class="hidden-xs hidden-sm">首页</li>
                <li class="active">地址管理</li>
            </ol>
        </div>
        <!-- 面包屑导航 E-->
        <div class="main clearfix">
            <!-- 左侧导航 -->
            <div class="left-nav f-fl col-md-4 hidden-xs hidden-sm">
                <div class="nav-main">
                    <a href="javascript:;" class="type-title">
                        <span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span>订单中心
                    </a>
                    <a href="/myorder/" class="ml ">我的订单</a>
                    
                    <a href="javascript:;" class="type-title">
                        <span class="glyphicon glyphicon-user" aria-hidden="true"></span>个人中心
                    </a>
                    <a href="{% url 'myhome_dizhi' %}" class="ml active">地址管理</a>                    
                    <a href="{% url 'myhome_xinxi' %}" class="ml ">个人信息</a>
                </div>
            </div>
            <!-- 左侧导航 E-->
            <!-- 右侧内容展示 -->
            <div class="right-content f-fr col-md-8 col-xs-12 col-sm-12">
                <div class="order-main">
                    <div id="tableList" class="type-contain ui-load-container">
                        <div class="panel panel-default">
                            <!-- Default panel contents -->
                            <div class="panel-heading">地址</div>
                            <!-- Table -->
                            <table class="table">
                                <thead>
                                    <tr>
                                        <th>收货人</th>
                                        <th>收货电话</th>
                                        <th>收货地址</th>
                                        <th>是否是默认地址</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for i in dizhi %}
                                    <tr>
                                        <th>{{ i.addressname }}</th>
                                        <td>{{ i.address }}</td>
                                        <td>{{ i.addressphone }}</td>
                                        <td>
                                            {% if i.status == 1 %}
                                                默认地址
                                            {% endif %}
                                        </td>
                                        <td>
                                            <a href="{% url 'myhome_dizhi' %}?did=d{{ i.id }}">删除</a>                                    
                                            <a href="{% url 'myhome_dizhi' %}?did=s{{ i.id }}">设为默认地址</a>
                                        </td>

                                    </tr>          
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                        <!-- 地址添加 -->
                    <div class="col-md-10">
                        <!-- 添加地址按钮 -->
                        <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
                          添加地址
                        </button>
                        <!-- 添加地址按钮E -->            
                        <!-- 添加地址窗口 -->
                        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                        <h4 class="modal-title" id="myModalLabel">地址添加</h4>
                                    </div>
                                    <div class="modal-body">
                                        <form>
                                            <div class="form-group">
                                                <label >收货人</label>
                                                <input type="text" name="addressname" class="form-control"  >
                                            </div>
                                            <div class="form-group">
                                                <label >收货地址</label>
                                                <input type="text" name="address" class="form-control"  >
                                            </div>
                                            <div class="form-group">
                                                <label>收货电话</label>
                                                <input type="text" name="addressphone" class="form-control" >
                                            </div>
                                            <div class="checkbox">
                                                <label>
                                                  <input type="checkbox" name="status" value="1"> 是否默认
                                                </label>
                                            </div>                                          
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                                <button type="button" class="btn btn-primary" id="CreateAddress">添加</button>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- 添加地址窗口E -->            
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


{% endblock %}


{% block script %}
<script type="text/javascript">
    //登录图片鼠标经过
    topLogin();
    backTop();      

    // 地址的添加
    $('#CreateAddress').click(function(){
        var data = {}
        //单机时候获取表单数据
        data.addressname = $(this).parents('form').find('input[name=addressname]').val()
        data.address = $(this).parents('form').find('input[name=address]').val()
        data.addressphone = $(this).parents('form').find('input[name=addressphone]').val()
        data.status = 0
        if($(this).parents('form').find('input[name=status]').prop('checked')){
            data.status = 1
        }

        // 发请求
        $.get('{% url "myhome_addressinsert" %}',data,function(data){
          if(data.error == 0){
            location.href = "/myorder/dizhi/"                
          }  
          alert(data.msg)
        })
    })


</script>
{% endblock %}}